package com.kotlin.mvpdemo.ui.users.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.kotlin.mvpdemo.databinding.ItemUserListBinding;
import com.kotlin.mvpdemo.entity.ChaptersEntity;

import java.util.List;

/**
 * author : fang.zhang
 * e-mail : initzf@126.com
 * date   : 2020/6/7
 * desc   :
 */
public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.UserListViewHolder> {

    private LayoutInflater mLayoutInflater;
    private List<ChaptersEntity> mDatas;

    public UserListAdapter(Context mContext) {
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public UserListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemUserListBinding inflate = ItemUserListBinding.inflate(mLayoutInflater, parent, false);
        return new UserListViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull UserListViewHolder holder, int position) {

        ChaptersEntity chaptersEntity = mDatas.get(position);
        holder.mListBinding.tvShowName.setText(chaptersEntity.getName());

    }

    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    public void setDatas(List<ChaptersEntity> mDatas) {
        if (mDatas == null) {
            return;
        }
        this.mDatas = mDatas;
        notifyItemRangeInserted(0, mDatas.size());
        //notifyDataSetChanged();
    }

    public static class UserListViewHolder extends RecyclerView.ViewHolder {

        public ItemUserListBinding mListBinding;

        public UserListViewHolder(@NonNull ItemUserListBinding itemView) {
            super(itemView.getRoot());
            this.mListBinding = itemView;
        }


    }
}
